CC = clang-18
SOURCE_PATH = src
DIST_PATH = dist
TARGET_NAME = clox

INCLUDE_PATH = $(SOURCE_PATH)/headers
FILES = $(wildcard $(SOURCE_PATH)/*.c)

TARGETS = $(patsubst $(SOURCE_PATH)/%.c, $(DIST_PATH)/%.o, $(FILES))

.PONY: clean 

clean:
	@-rm -f $(DIST_PATH)/*

$(TARGETS): $(DIST_PATH)/%.o: $(SOURCE_PATH)/%.c
	@$(CC)  -g  -I$(INCLUDE_PATH) -c $< -o $@

compile: $(TARGETS)
	@$(CC) $(TARGETS) -g -o $(DIST_PATH)/$(TARGET_NAME)
	@chmod +x $(DIST_PATH)/$(TARGET_NAME)
	@-rm -f $(DIST_PATH)/*.o

$(DIST_PATH)/$(TARGET_NAME): compile

run: $(DIST_PATH)/$(TARGET_NAME)
	@$(DIST_PATH)/$(TARGET_NAME) 